package com.hp.tiger.chapter5;

/**
 * @author XavierDong
 **/

/**
 * ShareResource
 */
public class Gate {

    private int counter = 0;
    private String name = "Nobody";
    private String address = "NoWhere";


    /**
     * 临界值
     *
     * @param name
     * @param address
     */
    public synchronized void pass(final String name, final String address) {
        this.counter++;
        /*race*/
        this.name = name;
        this.address = address;
        verify();
    }

    private void verify() {
        if (this.name.charAt(0) != this.address.charAt(0)) {
            System.out.println("******************BROKEN****************" + toString());
        }

    }


    @Override
    public synchronized String toString() {
        return "NO." + counter + ":" + name + "," + address;
    }
}
